package com.shenhaofeng.app.widget.viewpager;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;


/**
 * 可以控制滚动能力的ViewPager,默认情况下是禁止滚动的
 * Created by Administrator on 2016/7/22.
 */
public class ScrollableViewPager extends ViewPager {


    private boolean scrollEnable = false;


    public ScrollableViewPager(Context context) {
        super(context);
    }


    public ScrollableViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    /**
     * 设置滚动能力
     *
     * @param enable
     */
    public void setScrollEnable(boolean enable) {
        this.scrollEnable = enable;
    }


    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (scrollEnable) {
            return super.onTouchEvent(ev);
        }
        return false;
    }


    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (scrollEnable) {
            return super.onInterceptTouchEvent(ev);
        }
        return false;
    }
}
